package com.newtouch.cq.lang.result;

import com.newtouch.cq.lang.em.BaseExceptionEnum;
import com.newtouch.cq.lang.exception.IMccExceptionInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * 无数据返回对象
 *
 * @author Alex
 */
@Getter
@Setter
@ApiModel("返回对象")
public class MccResult  {
    public static final MccResult SUCCESS = new MccResult( BaseExceptionEnum.SUCCESS);
    public static final MccResult PLEASE_LOGIN = new MccResult( BaseExceptionEnum.ACCREDIT_INVALID_OVERDUE);

    @ApiModelProperty("code")
    protected String code;
    @ApiModelProperty("message")
    protected String message;

    public MccResult( IMccExceptionInfo info) {
        fillInfo(info);
    }

    private MccResult message(String message) {
        this.message = message;
        return this;
    }

    private MccResult code(String code) {
        this.code = code;
        return this;
    }

    public static MccResult successMsg(String message) {
        return MccResult.SUCCESS.message(message);
    }

    public static MccResult fail(IMccExceptionInfo info) {
        return new MccResult( info);
    }

    private MccResult fillInfo(IMccExceptionInfo<String> info) {
        if (null != info) {
            this.code = info.getCode();
            this.message = info.getMessage();
        }
        return this;
    }

    public static MccResult failureBmc(IMccExceptionInfo info) {
        return new MccResult( info);
    }

    public static MccResult failureBmc(String message) {
        return new MccResult( null).code(BaseExceptionEnum.FAIL.getCode()).message(message);
    }

}
